package com.example.mapping.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import com.example.mapping.common.core.ResultResponse;
import com.example.mapping.domain.Rule;
import com.example.mapping.dto.FlowModelDto;
import com.example.mapping.dto.FlowModelQueryDto;
import com.example.mapping.dto.RuleDto;
import com.example.mapping.dto.RuleQueryDto;
import com.example.mapping.manage.FlowModelManage;
import com.example.mapping.manage.RuleManage;
import com.example.mapping.sevice.RuleService;
import com.example.mapping.vo.FlowModelVo;
import com.example.mapping.vo.RuleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 规则controller类
 * @author baoyoujia
 */
@RestController
@RequestMapping("/rule")
public class RuleController {
    @Autowired
    private RuleManage ruleManage;

    @GetMapping("/rule")
    public ResultResponse<PageDTO<RuleVo>> getRuleListByPage(RuleQueryDto ruleQueryDto) {
        return ResultResponse.buildSuccess(ruleManage.getRuleByPage(ruleQueryDto));
    }

    @GetMapping("/{id}")
    public ResultResponse<RuleVo> get(@PathVariable("id") Long id) {
        return ResultResponse.buildSuccess(ruleManage.getRule(id));
    }

    @PostMapping("/rule")
    public ResultResponse<Boolean> add(@RequestBody RuleDto ruleDto) {
        return ResultResponse.buildSuccess(ruleManage.addRule(ruleDto));
    }

    @PutMapping("/{id}")
    public ResultResponse<Boolean> edit(@PathVariable("id") Long id, @RequestBody RuleDto ruleDto) {
        ruleDto.setId(id);
        return ResultResponse.buildSuccess(ruleManage.editRule(ruleDto));
    }

    @DeleteMapping("/{id}")
    public ResultResponse<Boolean> del(@PathVariable("id") Long id) {
        return ResultResponse.buildSuccess(ruleManage.delRule(id));
    }

}
